﻿using System;
using Csla.Xaml;
using Accounting.Library;
using System.ComponentModel;
using Utility;
using Accounting.Library.Utility;



namespace csla4Skeleton.UI.SL.TongHop.TH_KyGiaVon
{
    public class TH_KyGiaVon_ViewModel : ViewModel<Accounting.Library.TH_KyGiaVon>
    {
        #region Event Declare
        public delegate void ChildList_AddedNew_EventHandler(object sender, ChildListAddedNewArgs e);

        public event ChildList_AddedNew_EventHandler ChildList_AddedNew;
        public event EventHandler TimeChanged;
        public event EventHandler CountChanged;
        public event EventHandler LoadCompleted;
        #endregion

        #region Refresh Model
        public TH_KyGiaVon_ViewModel()
        {
            BeginRefresh("NewTH_KyGiaVon");
            
        }

        public TH_KyGiaVon_ViewModel(int Khoa)
        {
            BeginRefresh("GetTH_KyGiaVon", Khoa);
           
        }

        public TH_KyGiaVon_ViewModel(DateTime date)
        {
            BeginRefresh("GetTH_KyGiaVon", date.Month +";"+ date.Year);

        }

        public void NewTH_KyGiaVonViewModel()
        {
            BeginRefresh("NewTH_KyGiaVon");
            
        }

        public void GetTH_KyGiaVonViewModel(int Khoa)
        {
            BeginRefresh("GetTH_KyGiaVon", Khoa);
        }

       
        protected override void OnRefreshed()
        {
            base.OnRefreshed();
            if (Model != null)
            {
                Model.TH_KyGiaVon_ChiTiets.AddedNew += new EventHandler<Csla.Core.AddedNewEventArgs<TH_KyGiaVon_ChiTietChild>>(TH_KyGiaVon_ChiTiets_AddedNew);
                Model.TimeChanged += new EventHandler(OnTimeChanged);
                Model.CountChanged += new EventHandler(OnCountChanged);
                if (LoadCompleted != null)
                {
                    LoadCompleted(this, new EventArgs());
                }
            }
        }

        public void SaveAndNew()
        {
            BeginSave();
            NewTH_KyGiaVonViewModel();
        }
        public void SaveKyGiaVon()
        {
            BeginSave();
           
        }

        #endregion

        public void OnTimeChanged(object sender, EventArgs e)
        {

            if (TimeChanged != null)
            {
                TimeChanged(this, new EventArgs());
            }

        }

        public void OnCountChanged(object sender, EventArgs e)
        {

            if (CountChanged != null)
            {
                CountChanged(this, new EventArgs());
            }

        }

        #region Add TH_KyGiaVon Details Item
        public void AddTH_KyGiaVon_ChiTietItem()
        {
            Model.TH_KyGiaVon_ChiTiets.AddNewItem(Model.Khoa);
        }

       

        void TH_KyGiaVon_ChiTiets_AddedNew(object sender, Csla.Core.AddedNewEventArgs<TH_KyGiaVon_ChiTietChild> e)
        {
            OnChildList_AddedNew(sender, new ChildListAddedNewArgs("TH_KyGiaVon_ChiTiets"));
        }      

       

        protected virtual void OnChildList_AddedNew(object sender, ChildListAddedNewArgs e)
        {
            if (ChildList_AddedNew != null)
            {
                //Invokes the delegates.
                ChildList_AddedNew(sender, e);
            }
        }

      
        #endregion

        #region Delete TH_KyGiaVon Details Item

        public void DeleteTH_KyGiaVon_ChiTietItem(int Index)
        {
            Model.TH_KyGiaVon_ChiTiets.DeleteItem(Index);
        }

        #endregion

       
    }
}
